import request from '@/axios'
import type { Parameter } from './types'
let appName: string = ''
export const initAppName = (name: string) => {
  appName = name
}

export const getTableListApi = (params: Parameter) => {
  return request.get({ url: '/app/app' + appName + '/page', params })
}

export const getCardTableListApi = (params: any) => {
  return request.get({ url: '/app/app' + appName + '/page', params })
}

export const getOcrApi = (params: any) => {
  return request.get({ url: '/app/ocr/unify', params })
}

export const saveTableApi = (data: Partial<any>): Promise<IResponse> => {
  return request.post({ url: '/app/app' + appName + '/', data })
}

export const putTableApi = (data: Partial<any>): Promise<IResponse> => {
  return request.put({ url: '/app/app' + appName + '/1', data })
}

export const delTableApi = (id: any): Promise<IResponse> => {
  return request.delete({ url: '/app/app' + appName + '/' + id })
}

export const putDriverApi = (data: Partial<any>): Promise<IResponse> => {
  return request.put({ url: '/app/appDrivers/1', data })
}

export const getTableDetApi = (id: number): Promise<IResponse<any>> => {
  return request.get({ url: '/app/app' + appName + '/' + id })
}

export const delTableListApi = (ids: string[] | number[]): Promise<IResponse> => {
  return request.post({ url: '/mock/example/delete', data: { ids } })
}

export const updateTableApi = (data: Partial<FormData>): Promise<IResponse> => {
  return request.post({
    url: '/tool/oss/originals',
    data,
    headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' }
  })
}
